﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChurchData.Business
{
    public class PeopleKeywordBO : ChurchDataBusinessBase
    {
        #region Get Methods
        public IEnumerable<PeopleKeyword> GetRecordsByPeoplePK(int peoplePK)
        {
            ChurchDataDataContext oDB = new ChurchDataDataContext(this.GetConnectionString());

            return from rec in oDB.PeopleKeywords
                   where rec.PeopleFK == peoplePK
                   && rec.ActiveInd == true
                   orderby rec.LKKeyword.DescriptionText
                   select rec;
        }

        #endregion Get Methods

        #region Add Methods
        public void AddPeopleKeyword(int peoplePK, int lkKeyWordFK)
        {
            ChurchDataDataContext oDB = new ChurchDataDataContext(this.GetConnectionString());

            PeopleKeyword recNew = new PeopleKeyword();
            recNew.PeopleFK = peoplePK;
            recNew.LKKeywordFK = lkKeyWordFK;
            recNew.ActiveInd = true;
            recNew.LastUpdTimestamp = DateTime.Now;
            recNew.LastUpdUser = UserInformation.UserName;

            oDB.PeopleKeywords.InsertOnSubmit(recNew);
            oDB.SubmitChanges();
        }

        #endregion Add Methods

        #region Delete Methods
        public void DeletePeopleKeyword(int peopleKeywordPK)
        {
            ChurchDataDataContext oDB = new ChurchDataDataContext(this.GetConnectionString());

            PeopleKeyword rec = (from pk in oDB.PeopleKeywords
                                where pk.PeopleKeywordPK == peopleKeywordPK
                                select pk).First();

            rec.ActiveInd = false;
            rec.LastUpdUser = UserInformation.UserName;
            rec.LastUpdTimestamp = DateTime.Now;

            oDB.SubmitChanges();
        }

        #endregion Delete Methods
    }
}
